package com.burstly.lib.component.networkcomponent.burstly.html;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.burstly.lib.component.AbstractAdaptor.AdaptorListenerWrapper;
import com.burstly.lib.component.IBurstlyAdaptor.BurstlyAdType;
import com.burstly.lib.component.IBurstlyAdaptorListener;
import com.burstly.lib.component.IBurstlyAdaptorListener.FullscreenInfo;
import com.burstly.lib.component.ITrackClickResponseHandler;
import com.burstly.lib.component.LayoutParametersResolver;
import com.burstly.lib.component.networkcomponent.IActivityLifeCycleAware;
import com.burstly.lib.component.networkcomponent.burstly.AbstractBurstlyAdaptor;
import com.burstly.lib.component.networkcomponent.burstly.OverlayContainer.IOverlayListener;
import com.burstly.lib.component.networkcomponent.burstly.html.mraid.MraidView;
import com.burstly.lib.component.networkcomponent.burstly.html.ormma.OrmmaView;
import com.burstly.lib.component.networkcomponent.burstly.html.rewards.RewardsView;
import com.burstly.lib.component.networkcomponent.burstly.wrapper.WebViewClientWrapper;
import com.burstly.lib.network.beans.CreativeDataType;
import com.burstly.lib.network.beans.ResponseBean;
import com.burstly.lib.network.beans.ResponseBean.ResponseData;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.UiSafeWebView;
import com.burstly.lib.util.Utils;
import java.util.Map;

class BurstlyBaseScriptAdaptor extends AbstractBurstlyAdaptor
  implements WebViewFactory.IFactoryCallback, OverlayContainer.IOverlayListener
{
  static final IBurstlyAdaptorListener.FullscreenInfo FULLSCREEN_INFO = new IBurstlyAdaptorListener.FullscreenInfo("burstlyScript", false);
  private static final String HTML_WRAPPER = "<html><head><meta name='viewport' content='user-scalable=no initial-scale=1.0' /><title>Advertisement</title></head><body style=\"margin:0; padding:0; overflow:hidden; background-color:transparent;\"><div align=\"center\">?</div></body></html>";
  protected static final LoggerExt LOG = LoggerExt.getInstance();
  protected static final String NETWORK_NAME = "burstlyScript";
  boolean mCancelShow;
  protected String mDataToPost;
  private boolean mFullscreen;
  private boolean mPrecacheInterstitialRequest;
  protected String mScriptContent;
  private ScriptInterstitialOverlay<?> mScriptFullscreen;
  private boolean mSkipPause;
  protected UrlProvider mUrlProvider;
  private UiSafeWebView mWebView;

  BurstlyBaseScriptAdaptor(Context paramContext, String paramString)
  {
    super(paramContext, paramString);
    this.mTag = ("BurstlyScriptAdaptor" + paramString);
  }

  private void configureCommon(UiSafeWebView paramUiSafeWebView)
  {
    paramUiSafeWebView.setLayoutParams(getLayoutParamsResolver().resolveParameters());
    setWebView(paramUiSafeWebView);
  }

  private void createComponent()
  {
    new WebViewFactory(getContext(), getResponseData(), getFullResponse()).createImplementation(this, this.mFullscreen);
    if (!this.mFullscreen)
    {
      getWebView().setWebViewClient(new ScriptBannerWebClient((AbstractAdaptor.AdaptorListenerWrapper)getAdaptorListener(), "burstlyScript", this.mFullscreen, this.mUrlProvider));
      return;
    }
    RedirectClickListener localRedirectClickListener = new RedirectClickListener((AbstractAdaptor.AdaptorListenerWrapper)getAdaptorListener(), "burstlyScript", true, this.mUrlProvider);
    getWebView().setWebViewClient(new InterstitialLoadedWebViewClient(localRedirectClickListener));
  }

  private void getRequest(String paramString)
  {
    getWebView().loadUrl(paramString);
  }

  private void setFullscreen(ResponseBean.ResponseData paramResponseData)
  {
    Integer localInteger1 = paramResponseData.getIsInterstital();
    this.mFullscreen = Integer.valueOf(1).equals(localInteger1);
    if (!this.mFullscreen)
    {
      Integer localInteger2 = getFullResponse().getOffer();
      this.mFullscreen = Integer.valueOf(1).equals(localInteger2);
    }
  }

  private static String wrapHtmlIfNeed(String paramString)
  {
    if ((!paramString.contains("<html")) && (!paramString.contains("<HTML")) && (!paramString.contains("ormma")))
      paramString = "<html><head><meta name='viewport' content='user-scalable=no initial-scale=1.0' /><title>Advertisement</title></head><body style=\"margin:0; padding:0; overflow:hidden; background-color:transparent;\"><div align=\"center\">?</div></body></html>".replace("?", paramString);
    return paramString;
  }

  protected void checkParameters(Map<String, ?> paramMap)
    throws IllegalArgumentException
  {
    super.checkParameters(paramMap);
    ResponseBean.ResponseData localResponseData = getResponseData();
    setFullscreen(localResponseData);
    this.mUrlProvider = new UrlProvider(localResponseData.getUrl());
    this.mScriptContent = wrapHtmlIfNeed(localResponseData.getData());
    this.mDataToPost = localResponseData.getData();
    if (this.mUrlProvider.getUrl() == null)
      Utils.checkNotNull(this.mScriptContent, "Script content is null");
  }

  protected ScriptInterstitialOverlay<?> createFullscreenOverlay()
  {
    return new ScriptInterstitialOverlay(getWebView());
  }

  public void defaultViewCreated(UiSafeWebView paramUiSafeWebView)
  {
    configureCommon(paramUiSafeWebView);
    AbstractAdaptor.AdaptorListenerWrapper localAdaptorListenerWrapper = (AbstractAdaptor.AdaptorListenerWrapper)getAdaptorListener();
    getWebView().setWebViewClient(new RedirectClickListener(localAdaptorListenerWrapper, "burstlyScript", true, this.mUrlProvider));
  }

  public void destroy()
  {
    super.destroy();
    UiSafeWebView localUiSafeWebView = getWebView();
    if ((localUiSafeWebView != null) && ((localUiSafeWebView instanceof IActivityLifeCycleAware)))
    {
      ((IActivityLifeCycleAware)localUiSafeWebView).onDestroy(null);
      setWebView(null);
    }
  }

  protected View doGetNewAd()
  {
    this.mCancelShow = false;
    this.mPrecacheInterstitialRequest = false;
    createComponent();
    CreativeDataType localCreativeDataType = Utils.getDataTypeByCode(getResponseData().getDataType());
    String str = this.mUrlProvider.getUrl();
    if (str == null)
    {
      getWebView().loadDataWithBaseURL(null, this.mScriptContent, null, "utf-8", null);
      this.mScriptContent = null;
    }
    while (this.mFullscreen)
    {
      return null;
      if (localCreativeDataType == CreativeDataType.CreativeDataType_redirect)
        getRequest(str);
      else
        postRequest(str, this.mDataToPost);
    }
    return getWebView();
  }

  public IBurstlyAdaptor.BurstlyAdType getAdType()
  {
    if (this.mFullscreen)
      return IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE;
    return IBurstlyAdaptor.BurstlyAdType.BANNER_AD_TYPE;
  }

  public String getNetworkName()
  {
    return "burstlyScript";
  }

  public ITrackClickResponseHandler getResponseHandler()
  {
    return new ScriptClickResponseHandler(getContext(), getState(), this.mUrlProvider);
  }

  protected UiSafeWebView getWebView()
  {
    return this.mWebView;
  }

  public boolean isFullscreen()
  {
    return this.mFullscreen;
  }

  public boolean isPrecacheInterstitialRequest()
  {
    return this.mPrecacheInterstitialRequest;
  }

  public void mraidViewCreated(MraidView paramMraidView)
  {
    configureCommon(paramMraidView);
  }

  public void onCloseOverlay()
  {
    if (!isStopped())
    {
      getAdaptorListener().dismissedFullscreen(FULLSCREEN_INFO);
      this.mWebView.onDestroy((Activity)getContext());
      this.mFullscreen = false;
    }
  }

  protected void onInterstitialHtmlLoaded()
  {
    ScriptInterstitialOverlay localScriptInterstitialOverlay = this.mScriptFullscreen;
    this.mScriptFullscreen = createFullscreenOverlay();
    this.mScriptFullscreen.setOverlayListener(this);
    this.mScriptFullscreen.setInterstitialShowtime(getResponseData().getInterstitialShowtime());
    if (!isStopped())
    {
      if (this.mPrecacheInterstitialRequest)
        break label87;
      if ((localScriptInterstitialOverlay != null) && (localScriptInterstitialOverlay.isShowing()))
        getAdaptorListener().failedToLoad("burstlyScript", this.mFullscreen, "An interstitial is already showing");
    }
    else
    {
      return;
    }
    this.mScriptFullscreen.showOverlayed();
    return;
    label87: getAdaptorListener().didLoad("burstlyScript", true);
  }

  public void onShowOverlay()
  {
    if (!isStopped())
    {
      setHardwareAcceleration(getWebView());
      this.mSkipPause = true;
      IBurstlyAdaptorListener localIBurstlyAdaptorListener = getAdaptorListener();
      localIBurstlyAdaptorListener.didLoad("burstlyScript", true);
      localIBurstlyAdaptorListener.shownFullscreen(FULLSCREEN_INFO);
    }
  }

  public void ormmaViewCreated(OrmmaView paramOrmmaView)
  {
    configureCommon(paramOrmmaView);
  }

  @TargetApi(11)
  public void pause()
  {
    UiSafeWebView localUiSafeWebView = getWebView();
    if ((!this.mSkipPause) && (localUiSafeWebView != null))
      localUiSafeWebView.onPause((Activity)getContext());
    this.mSkipPause = false;
  }

  protected void postRequest(String paramString1, String paramString2)
  {
    byte[] arrayOfByte = null;
    if (paramString2 != null)
      arrayOfByte = Utils.getParamsBytes(paramString2);
    getWebView().postUrl(paramString1, arrayOfByte);
  }

  public View precacheAd()
  {
    return getNewAd();
  }

  public void precacheInterstitialAd()
  {
    precacheAd();
    this.mPrecacheInterstitialRequest = true;
  }

  @TargetApi(11)
  public void resume()
  {
    UiSafeWebView localUiSafeWebView = getWebView();
    if (localUiSafeWebView != null)
      localUiSafeWebView.onResume((Activity)getContext());
  }

  public void rewardsViewCreated(RewardsView paramRewardsView)
  {
    configureCommon(paramRewardsView);
  }

  protected void setFullscreen(boolean paramBoolean)
  {
    this.mFullscreen = paramBoolean;
  }

  public void setPrecacheInterstitialRequest(boolean paramBoolean)
  {
    this.mPrecacheInterstitialRequest = paramBoolean;
  }

  protected void setWebView(UiSafeWebView paramUiSafeWebView)
  {
    this.mWebView = paramUiSafeWebView;
  }

  public void showPrecachedInterstitialAd()
  {
    if (this.mScriptFullscreen != null)
      this.mScriptFullscreen.showOverlayed();
  }

  public void stop()
  {
    super.stop();
    this.mCancelShow = true;
  }

  public boolean supports(String paramString)
  {
    return true;
  }

  protected class InterstitialLoadedWebViewClient extends WebViewClientWrapper
  {
    private boolean mFired;

    InterstitialLoadedWebViewClient()
    {
      super();
    }

    InterstitialLoadedWebViewClient(WebViewClient arg2)
    {
      super();
    }

    public void onPageFinished(WebView paramWebView, String paramString)
    {
      super.onPageFinished(paramWebView, paramString);
      if ((!BurstlyBaseScriptAdaptor.this.isDestroyed()) && (!BurstlyBaseScriptAdaptor.this.mCancelShow) && (!this.mFired))
      {
        BurstlyBaseScriptAdaptor.this.onInterstitialHtmlLoaded();
        this.mFired = true;
      }
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.BurstlyBaseScriptAdaptor
 * JD-Core Version:    0.6.2
 */